package com.huanlis.workflow.server;

import com.alibaba.fastjson2.JSON;
import com.huanlis.workflow.server.domain.FlowEntity;
import com.huanlis.workflow.server.engine.FlowRepository;

import java.io.IOException;
import java.io.InputStream;

public class MainServer {

    @SuppressWarnings("rawtypes")
    public static void main(String[] args) {
//        ActionRegistry actionRegistry = new ActionRegistry();
//        String jarPath = "E:\\javaProject\\workflow\\workflow-server\\src\\main\\resources\\plugins\\custom-a-1.0.jar";
//        try (URLClassLoader classLoader = new URLClassLoader(new URL[]{new URL("file:" + jarPath)});) {
//            ServiceLoader<Action> serviceLoader = ServiceLoader.load(Action.class, classLoader);
//            for (Action action : serviceLoader) {
//                action.register(actionRegistry);
//            }
//        } catch (Exception e) {
//            throw new RuntimeException(e);
//        }
//        Map<String, String> actionClassNames = actionRegistry.getActionClassNames();
//        actionRegistry.getActions()
//                .forEach((k, v) -> {
//                    System.out.println("actionName: " + actionClassNames.get(k) + " -> " + "clazzName: " + k + " -> " + v.getClass().getName());
//                });

        String flowJson = "";

        try (InputStream inputStream = MainServer.class.getResourceAsStream("/flow.json")) {
            assert inputStream != null;
            byte[] bytes = inputStream.readAllBytes();
            flowJson = new String(bytes);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }


        FlowRepository flowRepository = new FlowRepository();
        FlowEntity flowEntity = JSON.parseObject(flowJson, FlowEntity.class);
        flowRepository.registerFlow(flowEntity);


    }


}
